package com.peg.rules;

import com.peg.dataobjects.Context;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegExpRule extends Rule{
    Pattern pattern;

    public RegExpRule(String pattern){
        this.pattern=Pattern.compile(pattern);
    }
    @Override
    public boolean execute(Context context) {
        if(context.EOL())return false;
        char c=context.getNextChar();
        Matcher m=pattern.matcher(""+c);
        boolean result = m.matches();
        return result;
    }

    @Override
    public String toString() {
        return "RegExpRule [" + pattern.pattern() +']';
    }
}
